class pxeserver (
  $syslinux_release = 'testing',
  $syslinux_stable_version = '6.03',
  $syslinux_testing_version = '6.04-pre1',
) {
  require apt::pxeserver

  file {
    '/etc/dnsmasq.conf':
      source => "puppet:///modules/${module_name}/dnsmasq.conf";

    '/var/lib/tftpboot/':
      source => "puppet:///modules/${module_name}/tftpboot/",
      recurse => true,
      force => true,
      purge => true;

    '/var/lib/tftpboot/prd/':
      ensure => directory,
      mode => '755';

    '/var/lib/tftpboot/prd/bios/':
      ensure => directory,
      mode => '755';

    '/var/lib/tftpboot/prd/efi64/':
      ensure => directory,
      mode => '755';

    '/var/lib/tftpboot/prd/pxelinux.cfg/':
      ensure => directory,
      mode => '755';

    '/var/lib/tftpboot/prd/pxelinux.cfg/default':
      source => "puppet:///modules/${module_name}/default";

    '/var/lib/tftpboot/prd/bios/pxelinux.cfg/':
      ensure => link,
      target => "../pxelinux.cfg";

    '/var/lib/tftpboot/prd/bios/chain.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/com32/chain/chain.c32";

    '/var/lib/tftpboot/prd/bios/ldlinux.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/com32/elflink/ldlinux/ldlinux.c32";

    '/var/lib/tftpboot/prd/bios/libcom32.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/com32/lib/libcom32.c32";

    '/var/lib/tftpboot/prd/bios/libutil.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/com32/libutil/libutil.c32";

    '/var/lib/tftpboot/prd/bios/memdisk':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/memdisk/memdisk";

    '/var/lib/tftpboot/prd/bios/menu.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/com32/menu/menu.c32";

    '/var/lib/tftpboot/prd/bios/lpxelinux.0':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/core/lpxelinux.0";

    '/var/lib/tftpboot/prd/bios/vesamenu.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/bios/com32/menu/vesamenu.c32";

    '/var/lib/tftpboot/prd/efi64/pxelinux.cfg/':
      ensure => link,
      target => "../pxelinux.cfg";

   '/var/lib/tftpboot/prd/efi64/chain.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/com32/chain/chain.c32";

    '/var/lib/tftpboot/prd/efi64/ldlinux.e64':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/com32/elflink/ldlinux/ldlinux.e64";

    '/var/lib/tftpboot/prd/efi64/libcom32.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/com32/lib/libcom32.c32";

    '/var/lib/tftpboot/prd/efi64/libutil.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/com32/libutil/libutil.c32";

    '/var/lib/tftpboot/prd/efi64/menu.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/com32/menu/menu.c32";

    '/var/lib/tftpboot/prd/efi64/syslinux.efi':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/efi/syslinux.efi";

    '/var/lib/tftpboot/prd/efi64/vesamenu.c32':
      ensure => link,
      target => "../../syslinux/${syslinux_release}/efi64/com32/menu/vesamenu.c32";

    '/var/lib/tftpboot/syslinux/stable':
      ensure => link,
      target => "./${syslinux_stable_version}";

   '/var/lib/tftpboot/syslinux/testing':
      ensure => link,
      target => "./${syslinux_testing_version}";

    '/usr/local/sbin/pxesync':
      source => "puppet:///modules/${module_name}/pxesync",
      owner => root,
      group => staff,
      mode => '750';
  }

  service {
    'dnsmasq':
      enable => true,
      subscribe => File['/etc/dnsmasq.conf'];
  }
}
